/**
 * 功能描述
 */

define(function (require, exports, module) {
	var tools = require("tools");
	var contractAwardDataSvc = require("../store/contractAwardDataSvc");
	
    module.exports = {
    		show:function(widget,data,disabled){
    			widget.show([".J-form"]).hide([".J-grid"]);
				widget.get("subnav").hide(["add","search","status","servicePoint","dateRange"]).show(["back"]);
				widget.get("form").reset();
				//会员基本信息
				widget.get("form").setValue("name", data.travelContract.member);
				widget.set("namevalue",data.travelContract.member.personalInfo.name+"--");
//				widget.get("form").setValue("pkMember", data.travelContract.member.pkMember);
				widget.get("form").setValue("idNumber", data.travelContract.member.personalInfo.idNumber);
				widget.get("form").setValue("sex", data.travelContract.member.personalInfo.sex.key);
				widget.get("form").setValue("mobilePhone", data.travelContract.member.personalInfo.mobilePhone);
				var birthdays = data.travelContract.member.personalInfo.birthday;
				if(birthdays!=null){
					var birthday = moment(birthdays).format('YYYY-MM-DD');
					var age = tools.getAgeByBirthdate(birthday);
					widget.get("form").setValue("age", age);
					widget.get("form").setValue("birthday", birthday);
				}
				var personalInfo = data.travelContract.member.personalInfo
				var address = personalInfo.houseRegister != null ? personalInfo.houseRegister : personalInfo.areaAddress != null ? personalInfo.areaAddress : personalInfo.contactAddresses.length == 0 ? "" : personalInfo.contactAddresses[0].address;
				var detailAddress = personalInfo.address != null ? personalInfo.address : personalInfo.contactAddresses.length == 0 ? "" : personalInfo.contactAddresses[0].detailAddress;
				if(address!=null){
					widget.get("form").setValue("administrative", address);
    			}
				widget.get("form").setValue("addressDetail", detailAddress);
				widget.get("form").setValue("balTimeSum",data.liveDays);
				widget.get("form").setValue("prices", data.price);
				//合同签约数据
				widget.get("form").setValue("contactNo", data.travelContract.contactNo);
				widget.get("form").setData("productRule", [{pkProduct:data.travelContract.productRule.product.pkProduct,name:data.travelContract.productRule.product.name}]);
				widget.get("form").setValue("productRule",data.travelContract.productRule.product.pkProduct);
				
				contractAwardDataSvc.getproductType(data.travelContract.productRule.product.pkProduct,function(productType){
					widget.get("form").setData("productType", productType);
					widget.get("form").setValue("productType", data.travelContract.productType.pkProductType);
                   });
				//pkProduct,productType
				contractAwardDataSvc.getproductBatch(data.travelContract.productRule.product.pkProduct,data.travelContract.productType.pkProductType,function(productBatch){
					widget.get("form").setData("productBatch", productBatch);
					widget.get("form").setValue("productBatch", data.travelContract.productBatch.pkProductBatch);
				});
				
				widget.get("form").setValue("productBatch", data.travelContract.productBatch == null ? null :data.travelContract.productBatch.pkProductBatch);
				widget.get("form").setValue("number", data.travelContract.number);
				widget.get("form").setValue("priceSum", data.travelContract.price);
				widget.get("form").setValue("memberCertificates", data.travelContract.memberCertificates);
				widget.get("form").setValue("signUpDate", data.travelContract.signUpDate);
				widget.get("form").setValue("startDate", data.travelContract.startDate);
				widget.get("form").setValue("endDate", data.travelContract.endDate);
				widget.get("form").setValue("description", data.travelContract.description);
				widget.get("form").setValue("pkTravelContract", data.travelContract.pkTravelContract);
				widget.get("form").setValue("version", data.travelContract.version);
				if(data.travelContract.unit.key == "Month"){
					widget.get("form").setValue("balTime","");
				}else{
					widget.get("form").setValue("balTime",data.travelContract.balTime);
				}
				widget.get("form").setValue("unit",data.travelContract.unit.key);
				widget.get("form").setDisabled("idNumber",true);
				widget.get("form").setDisabled("sex",true);
				widget.get("form").setDisabled("mobilePhone",true);
				widget.get("form").setDisabled("birthday",true);
				widget.get("form").setDisabled("age",true);
				widget.get("form").setDisabled("administrative",true);
				widget.get("form").setDisabled("addressDetail",true);
				if(disabled){
					widget.get("form").setDisabled(true);
				}
    		}
    };
});
